import request from '@/utils/server'

// 注册信息类型
export interface Params {
  phone: number | string
  password: string
  code: number | string
}

// user参数类型
export interface UserInfoData {
  name: string
  token: string
  headImg: string
  passwd: string
}

// 用户信息返回值类型
export interface resDataTwo {
  birthday: null
  createTime: string
  email: null
  gender: string
  headImg: string
  id: number
  loginName: string
  name: string
  nickName: string
  openId: null
  operateTime: string
  passwd: string
  phoneNum: string
  status: number
  userLevel: string
}
export interface UserInfoDataTwo {
  code: number
  data: resDataTwo
  message: string
  ok: boolean
}

// 登录参数类型
export interface LoginData {
  phone: number | string
  password: string
}

// 登录返回值类型
export interface logoinBackLogin {
  code: number
  data: resData
  message: string
  ok: boolean
}
export interface resData {
  name: string
  nickName: string
  token: string
  userId: number
}
/**
 * @desc：获取验证码
 * @param {*} phone 用户手机号
 * @returns Promise
 */
export const reqGetCode = (phone: string | number) => {
  return request.get(`/api/user/passport/sendCode/${phone}`)
}

/**
 * @desc 用户注册
 * @param {*} params phone:注册手机号,password:密码,code:验证码
 * @returns Promise
 */
export const reqRegister = (phone: number | string, password: string, code: number | string) => {
  return request.post('/api/user/passport/register', { phone, password, code })
}

/**
 * @desc 登录功能
 * @returns Promise
 */
export const reqLogin = (phone: number | string, password: string) => {
  return request.post<any, logoinBackLogin>('/api/user/passport/login', { phone, password })
}

/**
 * @desc 退出登录
 * @returns Promise
 */
export const reqLogout = () => {
  return request.get('/api/user/passport/logout')
}

/**
 * @desc 专门用于获取用户信息
 * @returns Promise
 */
export const reqUserInfo = () => {
  return request.get<any,UserInfoDataTwo>('/api/user/passport/auth/getUserInfo')
}
